const baseUrl = 'http://hunlian.huidn.com/'; // const baseUrl = 'http://192.168.1.151:8080'

export function magicApi(data) {
	return new Promise((resolve, reject) => {
		var header = {
			"Authori-zation": ""
		}; //参数类型

		if (data.Authorization == false) {
			uni.request({
				url: baseUrl + data.url,
				method: data.method,
				data: data.data ? data.data : data.params,
				success(result) {
					resolve(result);
				}
			});
		} else {
			uni.getStorage({
				key: 'Token',
				success: function(res) {
					header["Authori-zation"] = 'Bearer ' + res.data;
					uni.request({
						url: baseUrl + data.url,
						method: data.method,
						header: header,
						data: data.data ? data.data : data.params,
						success(result) {
							// console.log(result)
							if (result.data.status >= 410000) {
								uni.showToast({
									title: '请重新登录',
									success: () => {
										uni.removeStorage({
											key: 'Token'
										});
										setTimeout(() => {
											uni.redirectTo({
												url: '/pages/login/index'
											});
										}, 1200);
									}
								});
							}
							resolve(result.data);

						}
					});
				},
				fail: function(res) {
					reject();
				}
			});
		}

	});
}